#pragma once
#include "stdafx.h"
#include "Resource.h"
#include "DataStream.h"
#include "MeshLoader.h"
#include "ModelLoader.h"
#include "TextureLoader.h"
#include "ResourceMapping.h"
#define RESOURCE_DUMP_FILENAME "./log/resources.txt"

/*
ResourceManager manager all the resource.
But only some basic resource could load by it-self, like string ...
ResourceManager will use other assist component to help it load the resource.
To load the resource, there are some basic rule.
1. XXXLoader catch the message relatively.
2. XXXLoader parsing the data what the DataStream get.
3. XXXLoader use AddResource function to add the resource in ResourceManager
4. XXXLoader send the message to notisfy other component the resource is load.
*/

class MeshLoader;
class ModelLoader;
class TextureLoader;
class Component;

class ResourceManager : public Component
{
private:
	ResourceManager();
	ResourceManager(const ResourceManager&);
	
public:
	typedef boost::shared_ptr<ResourceManager> sPtr;
	typedef std::map< std::string, boost::shared_ptr<Resource> > ResourceMap;
	typedef std::map< Resource::ResourceType, ResourceMap> ResourceCatalog;
	ResourceManager(string);
	~ResourceManager(void);
	void AddedToObject();
	void Initial(const Message&);
	bool IsLoaded(Resource::ResourceType,string);
	void AddResource(Resource::ResourceType,string,Resource::sPtr);
	void RemoveResource(const Message& msg);
	void RemoveAllResource(const Message& msg);
	void GetResource(const Message& msg);
	Resource::sPtr GetResource(Resource::ResourceType, string);
	void Dump(const Message& msg);
	void DumpCatalog(Resource::ResourceType);
private:
	ResourceCatalog m_resourceCatalog;
	fstream m_dumpFile;
	string m_resMap;
	boost::shared_ptr<ResourceMapping> m_resMapping;
	boost::shared_ptr<MeshLoader> m_meshLoader;
	boost::shared_ptr<ModelLoader> m_modelLoader;
	boost::shared_ptr<TextureLoader> m_textureLoader;
};
